var searchLoginLock = false;
function searchLogin(){
	alert("Привет");
	if(searchLoginLock==false){
		searchLoginLock = true ;
		$("#spLoadData").css("display","inline-block");
		var login = $("#idLogin").val();
		$.post(
				"ajax/index.jsp", 
				{
					"action":"login_search",
					"login":log,
					"password":pwd,
				},
				function(data) {
					if(data.status=='ok'){
						if(data.userlogin == "used"){
							$("#spLoginInfo").css("color","#FF0000");
						}
						if(data.userlogin == "free"){
							$("#spLoginInfo").css("color","#00FF00");
						}
						$("#spLoginInfo").html(data.userlogin);
						$("#spLoginInfo").css("display","inline-block");
						$("#spLoadData").css("display","none");
						
					}
				},"json"
			);
		searchLoginLock=false;
	}
}

function addUser()
{
	if (lock == false) {
		lock = true;
		$("#spLoadData").css("display", "inline-block");
		var login = $("#idLogin").val();
		var password = $("#idPassword").val();
		$.post("ajax/index.jsp", {
		"action" : "login_search",
		"login" : login,
		"password" : password,
		}, function(data) {
		if (data.status == 'ok') {
		if (data.userlogin == "fail") {
		$("#spLoginInfo").css("color", "#FF0000");
		}
		if (data.userlogin == "succes") {
		$("#spLoginInfo").css("color", "#00FF00");
		}
		$("#spLoginInfo").html(data.username);
		$("#login").css("display", "none");
		$("#logged").css("display", "block");

		}
		}, "json");
		lock = false;
		}
}

function validateLogin()
{
	if($("#idRegNickname").val() != "")
	{
		var re = /^[a-zA-Z0-9]{2,15}$/;
		if ($("#idRegNickname").val().match(re)) {
		$("#errorNickname").css("display", "none");
		} else {
		$("#errorNickname").css("display", "block");
		}
	}
	else
	{$("#errorNickname").css("display", "none");}
}

function validateEmail()
{
	if($("#idRegEmail").val() != "")
	{
		var re = /^([\w\.-]{1,64}@[\w\.-]{1,252}\.\w{2,4})$/i;
		if ($("#idRegEmail").val().match(re)) {
		$("#errorEmail").css("display", "none");
		} else {
		$("#errorEmail").css("display", "block");
		}
	}
	else
	{$("#errorEmail").css("display", "none");}
}

function validatePass()
{
	if($("#idRegPassword").val() != "")
	{
		var re = /^(?!.*(.)\1{2})((?=.*[a-z])(?=.*[A-Z])(?=.*\d)).*$/gm;
		if ($("#idRegPassword").val().match(re)) {
		$("#errorPassword").css("display", "none");
		} else {
		$("#errorPassword").css("display", "block");
		}
	}
	else
	{$("#errorPassword").css("display", "none");}
}

function validateRePass()
{
	if($("#idRegPasswordRepeat").val() != "")
	{
		if ($("#idRegPassword").val() == $("#idRegPasswordRepeat").val()) {
			$("#errorPasswordRepeat").css("display", "none");
			} else {
			$("#errorPasswordRepeat").css("display", "block");
			}
	}
	else
	{$("#errorPasswordRepeat").css("display", "none");}
}

